/*
 * JSFConsole - Lightweight JSF Application Monitor
 * Copyright (C) 2009  Grzegorz Bugaj
 * http://www.gregbugaj.com
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/
package com.gregbugaj.reflector.filter;

import java.util.ArrayList;
import java.util.List;


public abstract class PropertyFilterStrategy {
	private final List<String> propertyList = new ArrayList<String>(); 

	/**
	 * Check what properties are visible for given object, ex EL accessible properties
	 * @param objectToInspect
	 */
	public abstract void inspect(final Object objectToInspect);
	/**
	 * Check if given property is known on the bean
	 * @param property to check
	 * @return true if the property is valid
	 */
	public abstract boolean isValidProperty(final String property);

	/*
 	public PropertyFilterStrategy(final String properties[]) {
		addProperties(properties);
	}

	 */

	public PropertyFilterStrategy addProperties(final String properties[]) {
		if (properties != null) {
			for (int i = 0; i < properties.length; i++) {
				addProperty(properties[i]);
			}
		}
		return this;
	}

	public PropertyFilterStrategy addProperty(final String property) {
		getPropertyList().add(property);
		return this;
	}

	public PropertyFilterStrategy removeProperty(final String property) {
		for (int i=0; i<getPropertyList().size(); i++) {
			if (getPropertyList().get(i).equals(property)) {
				getPropertyList().remove(i);
			}
		}
		return this;
	}

	public PropertyFilterStrategy removeProperties(final String properties[]) {
		if (properties != null) {
			for (int i = 0; i < properties.length; i++) {
				removeProperty(properties[i]);
			}
		}
		return this;
	}


	public int getPropertySize() {
		return getPropertyList().size();
	}

	public String[] getAllProperties() {
		return  getPropertyList().<String>toArray(new String [getPropertyList().size()]);
	}

	public List<String> getPropertyList() {
		return propertyList;
	}

	public void purge() {
		propertyList.clear();
	}
}
